<?php

//common mime types supported directly by browsers
$supported_mime_types = array(
    //registered IANA
    'js' => 'application/javascript',
    'pdf' => 'application/pdf',
    'mp3' => 'audio/mp3',
    'jpg' => 'image/jpeg',
    'jpeg' => 'image/jpeg',
    'png' => 'image/png',
    'gif' => 'image/gif',
    'svg' => 'image/svg+xml',
    'css' => 'text/css',
    'htm' => 'text/html',
    'html' => 'text/html',
    'mpeg' => 'video/mpeg',
    'mpg' => 'video/mpeg',
    'mp4' => 'video/mp4',
    'ogg' => 'video/ogg',
    'qt' => 'video/quicktime',
    'webm' => 'video/webm',
    //unregistered
    'jar' => 'application/x-jar',
    'jnlp' => 'application/x-java-jnlp-file',
    'wav' => 'audio/x-wav',
    'avi' => 'video/x-ms-wmv',
    'flv' => 'video/x-flv'
);

$str = substr( $_SERVER[ 'PATH_INFO' ], 1 );
$file = end( explode( DIRECTORY_SEPARATOR, $str ) );
$extension = end( explode( '.', $file ) );


if ( isset( $supported_mime_types[ $extension ] ) ) {

    header( 'Content-Type: ' . $supported_mime_types[ $extension ] );

    include 'app' . DIRECTORY_SEPARATOR . 'copperforest.inc.php';


    //Esto debería tener algún tipo de cacheo? en memoria o comprobando las cabeceras de la peticion
    $fp = fopen( CF_CLASS_PATH . strtr( $str,
                    array( '/' => DIRECTORY_SEPARATOR ) ), 'r' );

    while ( !feof( $fp ) ) {

        $data = fread( $fp, 4096 );
        echo $data;
    }

    fclose( $fp );
}
?>
